<template>
  <div class="user_right fl ml20">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="我的收藏" name="first">
        <div class="order_table c333 mt30">
          <table border="0" cellspacing="0" cellpadding="0" width="100%">
            <colgroup>
              <col width="200" />
              <col width="130" />
              <col width="150" />
              <col width="100" />
              <!-- <col width="120">
              <col width="100">-->
            </colgroup>
            <tbody>
              <tr>
                <th class="first">商品</th>
                <th>市场价</th>
                <th>会员价</th>
                <th class="last">操作</th>
              </tr>
            </tbody>
            <tbody v-if="collectionList">
              <tr v-for="(item,index) in collectionList" :key="item.id">
                <td style="display:flex;align-items:center">
                  <div class="pic-box">
                    <router-link :to="`/detail/${item.id}`" target="_blank">
                      <img :src="item.image" />
                    </router-link>
                  </div>
                  <div class="detail-box">
                    <ul>
                      <li>
                        <!-- :style="'border:1px solid '+item.brand.color+';color:'+item.brand.color" -->
                        <!-- <span class="brand">{{item.brand_name}}</span> -->
                        <router-link
                          :to="`/detail/${item.id}`"
                          target="_blank"
                        >{{item.series_name}} {{item.model_name}}</router-link>
                      </li>
                      <li v-if="item.parameters">
                        <span class="spec">
                          <span style="color:#333">参</span>
                          <span style="color:#333;margin-left: 13px;">数:</span>
                          {{Object.values(item.parameters).join('&emsp;|&emsp;')}}
                        </span>
                        <!-- <el-tooltip v-if="item.parameters" class="item" effect="dark" :content="Object.values(item.parameters).join('&emsp;|&emsp;')" placement="top">

                        </el-tooltip>-->
                      </li>
                      <li>
                        <label>
                          <span style="color:#333">型</span>
                          <span style="color:#333;margin-left: 14px;">号：</span>
                        </label>
                        <span class="stext">{{item.model_name}}</span>
                      </li>
                      <li>
                        <label>订货号：</label>
                        <span class="stext">{{item.part_number}}</span>
                      </li>
                    </ul>
                  </div>
                </td>
                <td
                  class="font-979797;text-align: center;"
                  style="text-decoration:line-through;text-align: center;"
                >¥{{item.price}}</td>
                <td
                  style="color: red;text-align: center;"
                >¥{{ Number(item.discount_price.toString().match(/^\d+(?:\.\d{0,2})?/)) }}</td>
                <td style="text-align: center;">
                  <el-button type="text" @click="cancels(item.id,index)">
                    <i class="el-icon-star-on">取消收藏</i>
                  </el-button>
                </td>
              </tr>
            </tbody>
          </table>
          <div class="center ptb20 mt40" v-if="collectionList == ''">
            <!-- <i class="ico_fail"></i> -->
            <img src="../../../assets/img/mydd.png" alt />
            <div class="f14 c999 mt10">您还没有收藏的商品哦~</div>
          </div>

          <!-- <ul class="" v-else>
            <li>
              <router-link to="" class="goA">
                <div class="hd">
                  <img src="~@/assets/img/s201803130433355169.jpg">
                </div>
                <div class="bd">
                    <p class="title">施耐德 Vigi iDPN附件 微型漏电模块附件</p>
                    <p class="price"><em>¥109.70</em>起</p>
                </div>
              </router-link>
            </li>
          </ul>-->
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { getCollectionList, deleteCollection } from '@/api/goods'
export default {
  name: 'rt-collect',
  metaInfo: {
    title: '我的收藏',
    titleTemplate: '工流界MRO一站式采购商城'
  },
  data () {
    return {
      activeName: 'first',
      hasMod: true,
      collectionList: []
    }
  },
  created () {
    this.getgoLista()
  },
  methods: {
    handleClick (tab, event) {
      console.log(tab, event)
    },
    async getgoLista () {
      const res = await getCollectionList()
      console.log(res)
      this.collectionList = res.data
    },
    async cancels (id, index) {
      await this.$confirm('此操作将取消收藏此商品, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          deleteCollection(id)
          this.collectionList.splice(index, 1)
          this.$message({
            type: 'success',
            message: '取消收藏成功!'
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.user_right {
  width: 950px;
  background: #fff;
  /deep/.el-tabs {
    padding-bottom: 40px;
    padding: 30px;
    .el-tabs__header {
      height: 40px;
      border-bottom: 1px solid #e6e6e6;
      .el-tabs__item {
        padding: 0 38px;
        height: 40px;
        box-sizing: border-box;
        line-height: 40px;
        display: inline-block;
        list-style: none;
        font-weight: 500;
        color: #303133;
        position: relative;
        font-size: 18px;
      }
      .el-tabs__item:hover {
        color: #4448f8;
      }
      .el-tabs__active-bar {
        height: 3px;
        background-color: #4448f8;
        width: 100px !important;
        transform: translateX(25px) !important;
      }
    }
    .el-tabs__content {
      color: #333;
      margin-top: 30px;
      table {
        width: 100%;
        border-collapse: collapse;
        border-spacing: 0;
        display: table;
        border-collapse: separate;
        border-spacing: 2px;
        border-color: grey;
        th.first {
          border-left: 1px solid #e6e6e6;
        }
        th {
          background: #f8f8f8;
          height: 38px;
          line-height: 38px;
          border: 1px solid #e6e6e6;
          border-left: none;
          border-right: none;
          text-align: center;
        }
        th.last {
          border-right: 1px solid #e6e6e6;
        }
      }
      .ptb20 {
        padding-top: 20px;
        padding-bottom: 20px;
      }
      .mt40 {
        margin-top: 40px;
      }
      .center {
        text-align: center;
        .ico_fail {
          background: url("~@/assets/img/fail_ico.png") no-repeat 0 0;
          width: 60px;
          height: 63px;
          display: inline-block;
        }
        p {
          color: #999;
          margin-top: 20px;
          font-size: 14px;
        }
      }
      // ul {
      //   overflow: hidden;
      //   margin-top: 28px;
      //   li {
      //     position: relative;
      //     float: left;
      //     width: 162px;
      //     height: 237px;
      //     margin-left: 20px;
      //     border: 1px solid #e6e6e6;
      //     box-sizing: border-box;
      //     .goA {
      //       display: block;
      //     }
      //     .hd {
      //       height: 160px;
      //       padding: 10px 0;
      //       box-sizing: border-box;
      //       text-align: center;
      //       img {
      //         max-width: 100%;
      //       }
      //     }
      //   }
      //   li:first-child {
      //   margin-left: 0;
      //   }
      //   li:hover {
      //     border-color: #4448f8;
      //     display: block;
      //   }
      //   li:before {
      //     position: absolute;
      //     content: '查看详情';
      //     width: 100%;
      //     line-height: 25px;
      //     left: 0;
      //     top: 0;
      //     color: #fff;
      //     background: red;
      //     text-align: center;
      //     background: rgba(68,72,248,.7);
      //   }
      // }
    }
    .c333 {
      color: #333;
    }
    .mt30 {
      margin-top: 30px;
    }
  }
}
.fl {
  float: left;
  display: inline;
}
.c999 {
  color: #999;
}
.f14 {
  font-size: 14px;
}
.mt10 {
  margin-top: 10px;
}
/*产品*/
.pic-box {
  float: left;
  display: inline-block;
  height: 105px;
  width: 105px;
}
.pic-box img {
  height: 85px;
  width: 85px;
  margin-top: 10px;
}
.detail-box {
  float: left;
  display: inline-block;
  margin-top: 10px;
  margin-left: 5px;
}
.detail-box ul {
  text-align: left;
  width: 250px;
}
.detail-box ul li {
  margin-top: 6px;
}
.detail-box ul li:first-child {
  margin-top: 2px;
}

.detail-box ul li label {
  display: inline-block;
  vertical-align: middle;
}
.detail-box ul li .stext {
  display: inline-block;
  vertical-align: middle;
  max-width: 200px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.w-140 {
  max-width: 140px !important;
}
.brand {
  display: inline-block;
  vertical-align: middle;
  padding: 2px 4px;
  border-radius: 2px;
  margin-right: 4px;
}
.detail-box ul li .spec {
  vertical-align: middle;
  display: inline-block;
  width: 240px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.detail-box ul li .name {
  color: #000;
  vertical-align: middle;
  line-height: 18px;
  margin-left: 3px;
  display: inline-block;
  width: 175px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.detail-box span {
  color: #979797;
}

.num-box a {
  font-size: 20px;
  display: inline-block;
  vertical-align: middle;
}
.num-box input {
  border: 1px solid #e6e6e6 !important;
  height: 26px;
  width: 50px;
  text-align: center;
}
</style>
